<%--
  Created by IntelliJ IDEA.
  User: LJJ
  Date: 2023/3/8
  Time: 15:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8"/>
    <title>查询仓库</title>

    <link href="css/all.css" rel="stylesheet" type="text/css">
    <link href="js/bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="js/bstable/css/bootstrap-table.css" rel="stylesheet" type="text/css">

</head>
<body>
<div>
    <div class="div_find">

        <p><label class="find_labela">仓库名：</label><input class="find_input" id="name">
            <%--        <option>全部</option>--%>
            <%--        <option>十一届</option>--%>
            <%--        <option>十二届</option>--%>
            <%--        <option>十三届</option>--%>
            <%--        <option>十四届</option>--%>
            <%--        <option>十五届</option>--%>

        </input><label class="find_labela">地址：</label><input class="find_input" id="address">
            <%--        <option>全部</option>--%>
            <%--        <option>立案提案</option>--%>


        </input>

            <input type="button" value="搜索一下" onclick="showWarehouse(1)" class="find_but" id="but_close">
            <input type="button" value="重置" onclick="clean()" class="find_but" id="but_close01"></p></div>
    <p class="p_but">

        <i class="down_i"></i><a href="#" class="add_a">导出</a>
        <i class="print_i"></i><a href="#" class="add_a">打印</a>
    </p>

    <p>
    <table id="table" class="table" style="margin: 0 auto">
    </table>
    </p>
    <div id="page">

    </div>
</div>
<div class="modal fade" id="test1" role="dialog">
    <div class="modal-dialog" role="document" style="width: 85%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="myModalLabel1">修改仓库信息</h4>
            </div>
            <div class="modal-body">

                <form class="form-horizontal" role="form" id="createActivityForm">

                    <div class="form-group">
                        <label for="no" class="col-sm-2 control-label">编号</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="no" readonly="readonly">

                            <%--                        <select class="form-control" id="create-marketActivityOwner">--%>
                            <%--<option>zhangsan</option>
                            <option>lisi</option>
                            <option>wangwu</option>--%>

                            <%--                        </select>--%>
                        </div>
                        <label for="warehouseName" class="col-sm-2 control-label">仓库名<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="warehouseName" onmouseout="">
                        </div>


                    </div>

                    <div class="form-group">
                        <label for="warehousePhone" class="col-sm-2 control-label">电话<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" onmouseout="hidePhoneError()"
                                   id="warehousePhone"><span id="phoneError" hidden="hidden"
                                                             style="font-size: 15px; color: red;">号码不规范</span>
                        </div>
                        <label for="warehouseAddress" class="col-sm-2 control-label">地址<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="warehouseAddress">
                        </div>
                    </div>


                    <%--                <span id="activityMsg" style="color: red;position: absolute;left: 180px"></span>--%>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="saveActivityBtn" type="button" class="btn btn-primary" onclick="updateWarehouse()">保存
                </button>
            </div>
        </div>
    </div>
</div>

<script src="js/jquery/jQuery-2.2.0.min.js"></script>
<script src="js/bstable/js/bootstrap.min.js"></script>
<script src="js/bstable/js/bootstrap-table.js"></script>
<script src="js/bstable/js/bootstrap-table-zh-CN.min.js"></script>
<script src="js/date/js/laydate.js"></script>

<script>
    showWarehouse(1);

    function showWarehouse(pageNum) {
        $.ajax({
            url: "queryWarehouse.do",
            type: "POST",
            data: {
                "name": $("#name").val(),
                "address": $("#address").val(),
                "pageNum": pageNum,
                "pageSize": 10
            },
            dataType: "json",
            success: function (datas) {
                var str = "";
                str += "<tr><th>编号</th><th>仓库名</th><th>电话</th><th>地址</th><th>操作</th></tr>"
                var data = datas.list;
                for (var i = 0; i < data.length; i++) {
                    str += "<tr>"
                    str += "<td>" + data[i].id + "</td>"
                    str += "<td>" + data[i].name + "</td>"
                    str += "<td>" + data[i].phone + "</td>"
                    str += "<td>" + data[i].address + "</td>"
                    str += "<td><a href='#' onclick='update(" + JSON.stringify(data[i]) + ")'>修改</a><a href='#' onclick='deleteWarehouse(" + data[i].id + ")'>删除</a></td>"
                }
                $("#table").html(str)
                var cutPage = "";
                for (var i = 1; i <= datas.pages; i++) {
                    cutPage += "<a href='#' onclick='showWarehouse(" + i + ")'>" + i + "</a>&nbsp"
                }
                $("#page").html(cutPage)

            }

        })
    }

    function update(data) {
        hidePhoneError()
        var data1 = eval(data);
        $("#no").val(data1.id)
        $("#warehouseName").val(data1.name)
        $("#warehousePhone").val(data1.phone)
        $("#warehouseAddress").val(data1.address)


        $("#test1").modal("show")
    }

    function clean() {
        $("#name").val("");
        $("#address").val("");
        showWarehouse(1);
    }

    function deleteWarehouse(id) {
        $.ajax({
            url: "deleteWarehouse.do",
            type: "post",
            data: {
                "id": id
            },
            dataType: "json",
            success: function (data) {
                alert(data.msg)
                if (data.code == "1") {
                    window.location.reload()
                }
            }
        })
    }

    function updateWarehouse() {

        var count = 0
        var reg = /^[7]\d{6}/
        const warehouseName = $("#warehouseName")
        const warehousePhone = $("#warehousePhone")
        const warehouseAddress = $("#warehouseAddress")

        if (warehouseName.val() == "" || warehousePhone.val() == "" || warehouseAddress.val() == "") {
            count += 1
        }
        if (!reg.test(warehousePhone.val())) {
            count += 1
            $("#phoneError").show()
        }

        if (count > 0) {
            alert("请规范填写")
            return false
        }

        $.ajax({
            url: "updateWarehouse.do",
            type: "POST",
            data: {
                "id": $("#no").val(),
                "name": $("#warehouseName").val(),
                "phone": $("#warehousePhone").val(),
                "address": $("#warehouseAddress").val(),

            },

            dataType: "json",
            success: function (data) {
                alert(data.msg)
                if (data.code == "1") {
                    window.location.reload()
                }
            }
        })
    }

    function hidePhoneError() {
        $("#phoneError").hide()
    }


</script>


</body>
</html>
